package cn._51doit.flink.day02.transformations;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * 使用java8的lambda表达式完成map功能
 */
public class MapDemo {

    public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<String> lines = env.socketTextStream("localhost", 8888);

        //lines.map(e => e.toUpperCase)
        //SingleOutputStreamOperator<String> upperStream = lines.map(e -> e.toUpperCase());
        //lines.map(_.toUpperCase)
        MapFunction<String, String> mapFunction = new MapFunction<String, String>() {
            @Override
            public String map(String s) throws Exception {
                return s.toUpperCase();
            }
        };
        //SingleOutputStreamOperator<String> upperStream = lines.map(String::toUpperCase);
        SingleOutputStreamOperator<String> upperStream = lines.map(mapFunction);

        upperStream.print();

        env.execute();
    }

}
